<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>ESMS</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" href="/ssm_esms/static/css/font.css">
  <link rel="stylesheet" href="/ssm_esms/static/css/xadmin.css">
  <script type="text/javascript" src="/ssm_esms/static/js/jquery-3.3.1.js"></script>
  <script type="text/javascript" src="/ssm_esms/static/lib/layui/layui.js"></script>
  <script type="text/javascript" src="/ssm_esms/static/js/xadmin.js"></script>
  <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
  <!--[if lt IE 9]>
  <!--<script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>-->
  <!--<script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>-->
  <!--<![endif]&ndash;&gt;-->

</head>

<body class="layui-anim layui-anim-up">

<div class="x-nav">
      <span class="layui-breadcrumb">
        <a >首页</a>
        <a >部门管理</a>
        <a>
          <cite>部门列表</cite></a>
      </span>
  <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body" id="container">
  <div class="layui-row">
    <div class="demoTable  layui-col-md11 layui-form">
      部门名称：
      <div class="layui-inline">
        <input class="layui-input" name="id" id="demoReload" autocomplete="off">
      </div>
      <button class="layui-btn" data-type="reload">搜索</button>
    </div>
    <!--<xblock>-->
      <!--<button class="layui-btn" onclick="x_admin_show('添加','toPage.do?url=admin/department-add.html',600,400)"><i class="layui-icon"></i>添加</button>-->
    <!--</xblock>-->
    <div class="layui-col-md1">
      <div class="layui-inline">
        <button class="layui-btn" style=" margin-top: 0px;padding: 2px 10px 4px 10px" onclick="x_admin_show('添加','toPage.do?url=admin/department-add.html',600,400)"><i class="layui-icon"></i>添加</button>
      </div>
    </div>
  </div>



  <div style="text-align: center">
    <table class="layui-table" lay-data="{height: 'full-160', cellMinWidth:80, url:'department/findSelective.do', page:true, id:'idTest'}" lay-filter="demo">
      <thead>
      <tr>
        <th lay-data="{field:'dName', width:300, fixed: true,align: 'center'}">部门名称</th>
        <th lay-data="{field:'dRemark', minWidth:400,align: 'center'}">部门备注</th>
        <th lay-data="{fixed: 'right', width:295, align:'center', toolbar: '#barDemo'}"></th>
      </tr>
      </thead>
    </table>
  </div>

</div>
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script>
    layui.use('table', function(){
        // layui.use(['form', 'table','layedit', 'laydate'], function(){
        var table = layui.table;

        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
                layer.msg('ID：'+ data.id + ' 的查看操作');
            } else if(obj.event === 'del'){
                layer.confirm('确定要删除吗', function(index){
                    // console.log(data);
                    $.ajax({
                        type:'post',
                        url:'department/deleteByPrimaryKey.do',
                        data: {"id":data.dId},
                        dataType:'json',
                        success:function(data){
                            if (data == 1) {
                                layer.msg('已删除!', {icon: 1, time: 4000});
                                // $(obj).parents("tr").remove();
                                obj.del();

                            }
                            else {
                                //alert("exist");
                                layer.msg('删除失败!', {icon: 5, time: 1000});
                            }
                        },
                        error: function (data) {
                            // alert("error" + data);
                            layer.alert("抱歉！出现未知错误！", {icon: 5});
                        }

                    });
                    obj.del();
                    layer.close(index);
                    // location.reload();
                });
            } else if(obj.event === 'edit'){
                // layer.alert('编辑行：<br>'+ JSON.stringify(data));
                x_admin_show('编辑','toPage.do?url=admin/department-edit.html?dId='+data.dId+'&dName='+data.dName+'&dRemark='+data.dRemark, 600,400);

            }
        });

        var $ = layui.$, active = {

            reload: function(){
                var demoReload = $('#demoReload');
                // alert("asd");
                //执行重载
                table.reload('idTest', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        d_name: demoReload.val()
                    }
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });



    });

</script>

</body>

</html>